//
//  HMSearchView.swift
//  Weibo
//
//  Created by 黄亦寒 on 16/9/19.
//  Copyright © 2016年 HM. All rights reserved.
//

import UIKit

class HMSearchView: UIView {

    @IBOutlet weak var searchTextFieldRightConstraint: NSLayoutConstraint!
    
    @IBOutlet weak var searchButton: UIButton!

    @IBOutlet weak var searchTextField: UITextField!
    
    @IBAction func editBeginAction(_ sender: AnyObject) {
        //当点击搜索输入框时向左缩小一个搜索按钮的宽度
        searchTextFieldRightConstraint.constant = searchButton.width
        //缩小时添加动画效果
        UIView.animate(withDuration: 0.3){
            self.layoutIfNeeded()
        }
    }
    
    @IBAction func searchButtonAction(_ sender: AnyObject) {
        //当点击搜索按钮时收回键盘同时让输入框恢复原来的大小
        searchTextField.resignFirstResponder()
        searchTextFieldRightConstraint.constant = 0
        //恢复大小时添加动画效果
        UIView.animate(withDuration: 0.3){
            self.layoutIfNeeded()
        }
    }
    
    //使用类方法创建xib对象
    class func searchView() -> HMSearchView {
        return UINib(nibName:"HMSearchView",bundle:nil).instantiate(withOwner: nil, options: nil).last as! HMSearchView
        
    }
    
    
    
    
    
}
